<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta name="renderer" content="webkit">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<!-- Font Awesome -->
		<!-- Ionicons -->
		<!-- Theme style -->
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<!-- AdminLTE Skins. Choose a skin from the css/skins
		       folder instead of downloading all of them to reduce the load. -->
		<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
		<title></title>
		<style>
			p,
			body {
				margin: 0;
			}
			
			p {
				font-size: .27rem;
				letter-spacing: 1px;
			}
			
			body {
				background: url(img/downloan.png) no-repeat;
				background-size: 100% auto;
			}
			
			.content {
				margin: 0 .3rem;
				/*background-color: #ccc;*/
				/*height:5rem;*/
			}
			
			label {
				line-height: 34px;
				margin: 0;
				font-weight: normal;
				text-indent: 15px;
			}
			
			input.form-control,
			input.form-control:disabled {
				border: none;
				background-color: rgba(0, 0, 0, 0);
			}
			
			.form-group {
				padding-bottom: 10px;
				border-bottom: 1px solid #ccc;
			}
			
			.form-group .col-xs-3,
			.form-group .col-xs-4,
			.form-group .col-xs-5,
			.form-group .col-xs-6,
			.form-group .col-xs-9 {
				padding: 0;
			}
			
			.btn {
				font-size: 15px;
				border-radius: 26px;
				line-height: 35px;
				color: #fff;
				background-color: #D32D26;
			}
			.control-label{
				font-size:12px;
			}
			input.form-control{
				font-size:12px;
			}
		</style>
		<script>
			window.onload = function() {
				getRem(720, 100)
			};
			window.onresize = function() {
				getRem(720, 100)
			};

			function getRem(pwidth, prem) {
				var html = document.getElementsByTagName("html")[0];
				var oWidth = document.body.clientWidth || document.documentElement.clientWidth;
				html.style.fontSize = oWidth / pwidth * prem + "px";
			}
		</script>
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
	</head>

	<body>
		<div style="height:4.8rem;"></div>
		<div class="content">	
			<form class="form-horizontal">
				<div class="box-body">
					<div class="form-group">
						<label for="phone" class="col-xs-3 control-label">手机号码</label>
						<div class="col-xs-9">
							<input type="text" class="form-control" id="phone" placeholder="请输入手机号">
						</div>
					</div>
					<div class="form-group">
						<label for="Password" class="col-xs-3 control-label">登录密码</label>
						<div class="col-xs-9">
							<input type="Password" class="form-control" id="Password" placeholder="请输入登录密码">
						</div>
					</div>
					<div class="form-group">
						<label for="smsCode" class="col-xs-3 control-label">验证码</label>
						<div class="col-xs-5">
							<input type="number" class="form-control" id="smsCode" placeholder="请输入验证码">
						</div>
						<div class="col-xs-4">
							<div style="line-height:34px;text-align:center;font-size:12px;" id="getCode">获取验证码</div>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="col-xs-3 control-label">邀请码</label>
						<div class="col-xs-9">
							<input type="text" class="form-control" disabled="disabled" id="directUserCode" placeholder="">
						</div>
					</div>
				</div>
			</form>
			<button type="button" class="btn btn-default btn-block" id="login">立即注册</button>
			<a href="javascript:;" id="ToDownload" style="display:inline-block;color:#999;margin:15px 0;font-size:12px;">我已注册立即下载</a>
		</div>
		<script type="text/javascript" src="js/fr.js"></script>
		<script type="text/javascript" src="js/fr_func.js"></script>
		<script type="text/javascript">
			function phoneSystem() {
				var phone = ""
				var u = navigator.userAgent,
					app = navigator.appVersion;
				console.log(u);
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
				var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
				if(isAndroid) {
					console.log(111);
					//这个是安卓操作系统
					phone = "Android";
				}
				if(isIOS) {
					console.log(222);　　　　 //这个是ios操作系统
					phone = "IOS";
				}
				return phone;
			}

			function getUrl() {
				var url = location.search;
				var json = {};
				if(url.indexOf("?") != -1) {
					//					console.log(111);
					var str = url.substr(1);
					strs = str.split("&");
					var arr = strs[0].split("=");
					var keyStr = "";
					for(var i = 0; i < arr.length; i++) {
						if(i != 0) {
							if(i != 1) {
								keyStr += "=" + arr[i];
							} else {
								keyStr += arr[i];
							}
						}
					}
					json[arr[0]] = keyStr;
				}
				return json;
			}
			$(function() {
				var IOSdownloan = "https://www.pgyer.com/7LiV";
				var AndroidDownloan = "https://fir.im/j67p";

				console.log(phoneSystem())
				if(getUrl().directUserCode) {
					console.log(getUrl().directUserCode);
					$("#directUserCode").val(getUrl().directUserCode);
				};

				var btn = $("#getCode");
				var wait = 60;
				var isPress = false;
				$("#getCode").click(function() {
					function time() {
						if(wait == 0) {
							btn.html("获取验证码");
							wait = 60;
							isPress = false;
						} else {
							btn.html("重新获取" + wait + "s");
							wait--;
							setTimeout(function() {
								time();
							}, 1000)
						}
					}
					if(isPress) {
						return;
					} else {
						isPress = true;
						var code;
						$.ajax({
							type: "POST",
							url: url + "/app/user/getSmsCode",
							async: false,
							data: JSON.stringify({
								phone: $("#phone").val()
							}),
							contentType: "application/json",
							dataType: "json",
							success: function(res) {
								if(res.returnCode == "200") {
									time();
									return;
								} else {
									isPress = false;
									alert(res.msg);
								}
							}
						});
					}
				});

				$("#login").click(function() {
					var param = {
						phone: $("#phone").val(), //手机号
						password: $("#Password").val(), //登录密码
						smsCode: $("#smsCode").val(), //短信验证码
						directUserCode: $("#directUserCode").val() //邀请码密文
					}
					console.log(param);
					//					return false;
					$.ajax({
						type: "post",
						url: url + "/app/user/register",
						//  					async:"true",
						data: JSON.stringify(param),
						contentType: "application/json",
						dataType: "json",
						success: function(res) {
							if(res.returnCode == 200) {
								alert("注册成功！确定跳转")
								if(phoneSystem() == "IOS") {
									window.location.href = IOSdownloan;
								} else {
									window.location.href = AndroidDownloan;
								}

							} else {
								alert(res.msg)
							}
						},
						error:function(res){
							alert('请求报错')
						}
					})
				})

				$("#ToDownload").click(function() {
					if(phoneSystem() == "IOS") {
						window.location.href = IOSdownloan;
					} else {
						window.location.href = AndroidDownloan;
					}

				})
			})
		</script>
	</body>

</html>